package StudyCode.summary.zipfile;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateFilesWithLambdaStream {
	public static void createFiles(Path parent, String prefix, int count)
			throws IOException {
		createFiles(parent, prefix, count, ".txt");
	}

	public static void createFiles(Path parent, String prefix, int count,
	                               String suffix) throws IOException {
		createFiles(parent, prefix, 0, count, suffix);
	}

	public static void createFiles(Path parent, String prefix, int start, int end, String suffix)
			throws IOException {
//		IntStream.range(start, end)
//				.mapToObj(i -> prefix + i + suffix)
//				.map(parent::resolve)
//				.forEach(CommonTestUtils::write);
	}

	private static final List<String> BODY = Arrays.asList("test\n");

	public static void write(URI uri) throws IOException {
		write(Paths.get(uri));
	}

	public static void write(Path p) {
		try {
			Files.write(p, BODY, StandardOpenOption.CREATE,
					StandardOpenOption.WRITE);
		} catch (IOException ex) {
			throw new UncheckedIOException(ex);
		}
	}
}
